package cn.golxen.rsms.commons.utils;

import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.util.Properties;

public class YmlUtils {
    static Properties ymlObject;
    //获取yml文件中的属性配置
     static {
        Resource resource = new ClassPathResource("/config.yml");
        Properties properties = null;
        try {
            YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
            yamlFactory.setResources(resource);
            properties =  yamlFactory.getObject();
        } catch (Exception e) {
            e.printStackTrace();
        }
        assert properties != null;
        ymlObject= properties;
    }

    public static String getString(String key){
         try {
             return (String) ymlObject.get(key);
         }catch (ClassCastException e){
             return String.valueOf(ymlObject.get(key));
         }

    }

    public static Integer getInt(String key){
        return (Integer) ymlObject.get(key);
    }

}
